html = """
<div id="continer">
    <ul class="list">
        <li class="item-0 active">first item</li>
        <li class="item-1active"><a href="test.html">second item</a> </li>
        <li class="item-0active"><span href="test.html"><span class="ansi-bold"></span> third item</span></a></li>
        <li class="item-1"><a href="test.html">forth item</a></li>
        <li class="item-0"><a href="test.html">fifth item</a></li>
        <li class="item-1"><a href="test.html">sixth item</a></li>
    </ul>
</div>
"""
from pyquery import PyQuery as pq
# doc = pq(html)
# print(doc('li'))
# url初始化
# doc = pq(url='https://home.firefoxchina.cn/')
# print(doc('head'))`
# 文件初始化
# doc = pq(filename='test.html')
# print(doc('li'))
# 基本css选择器,id前面加一个#，class前面加一个.,其他不加
# 只要有层级关系就行，不一定非要层级关系
doc = pq(html)
# print(doc('#continer .list li'))
# 查找子元素
# items = doc('.list')
# # print(items)
# # lis = items.find('li')
# # print(lis)
# lis = items.children('active')
# 查找父元素
# items = doc('.list')
# lis = items.parent()
# print(lis)
# 查找祖先节点
# items = doc('.list')
# lis = items.parents()
# print(lis)
# 查找兄弟节点
# li = doc('.list .item-0active')
# print(li.siblings())
# 遍历
# lis = doc('li').items()
# for li in lis:
#     print(li)
# 获取属性
# a = doc('.item-0 a')
# print(a.attr('href'))
# 获取文本
# a = doc('.item-0 a')
# print(a.text())
# 获取html
# a = doc('.item-0active')
# print(a.html())
# 操作dom 添加删除属性
# li = doc('.item-0.active')
# print(li)
# li.remove_class('active')
# print(li)

# li.add_class('active')
# print(li)

# li = doc('.item-0.active')
# li.attr('name','link')
# print(li)
# remove方法
html1 = """
<div class="warp">
    Hello word
    <p>this is python</p>
</div>
"""
# doc = pq(html1)
# warp = doc('.warp')
# print(warp.text())
# warp.find('p').remove()
# print(warp.text())